<?php namespace Common\Model;
use Hdphp\Model\Model;
class Address extends Model{
	//指定表名
	protected $table='user_address';
	//自动验证
	protected $validate=[
		['name','required','收货人姓名不能为空',3,3],
		['phone','required','收货人电话不能为空',3,3],
		['address','_address','请填写正确的收货地址',3,3]
	];
	//自定义验证
	public function _address(){
	    $address=Q('post.address');
		foreach($address as $v){
			if($v=='0' || $v==''){
				return FALSE;
			}
		}
		return TRUE;
	}
	//添加地址
	public function store(){
		if(!$this->create()) return FALSE;
		$address=Q('post.address');
		$this->data['address']=implode(',', $address);
		return $this->add();
	}
	//编辑地址
	public function edit(){
		if(!$this->create()) return FALSE;
		$address=Q('post.address');
		$this->data['address']=implode(',', $address);
		return $this->save();
	}
}
 ?>